package ui;

import config.GameConfig;
import dto.Player;

import java.awt.*;
import java.util.List;

public abstract class LayerData extends Layer{
    /**
     *  最大数据行
     */
    private static final int MAX_ROW = GameConfig.getDataConfig().getMaxRow();
    /**
     * 起始Y坐标
     */
    private static  int STATR_Y = 0;
    /**
     * 间距
     */
    private static int SPA = 0;
    /**
     * 值槽外径
     */
    private static final int RECT_H = IMG_RECT_H + 4;

     public LayerData(int x,int y,int w,int h){
        super(x,y,w,h);
        //计算记录绘制间距
         SPA = (this.h - RECT_H * 5 - (PADDING << 1) - Img.DB.getHeight(null)) / MAX_ROW;
         //计算起始Y坐标
         STATR_Y = PADDING + Img.DB.getHeight(null) +SPA;
    }
    /**
     * 绘制所以值槽
     */
    public void showData(Image imgTitle, List<Player> players,Graphics g){
        g.drawImage(imgTitle,this.x+PADDING,this.y+PADDING,null);
        int nowPoint = this.dto.getNowPoint();
        for (int i = 0;i < MAX_ROW;i++){
            Player pla = players.get(i);
            int recodePoint = pla.getPoint();
            double percent = (double) nowPoint /  recodePoint;
            percent = percent > 1 ? 1.0:percent;
            String strPoint = recodePoint == 0 ? null : Integer.toString(recodePoint);
            this.drawRect(STATR_Y + i * (RECT_H + SPA),
                    pla.getName(),strPoint,
                    percent,g);
        }
    }
    @Override
    abstract public void paint(Graphics g);
}
